package org.base.sys.controller;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;
import org.springframework.validation.annotation.Validated;
import org.base.common.controller.BaseController;
import org.base.sys.pojo.SysUserRole;
import org.base.sys.service.SysUserRoleService;
import org.base.sys.query.SysUserRoleQuery;
import java.util.List;
import javax.validation.Valid;

import org.base.common.pojo.PageResult;

/**
 * <p>
 * 用户和角色关联 前端控制器
 * </p>
 *
 * @author AutoGenerator
 * @since 2020-05-27
 */
@Api(value = "用户和角色关联", tags = "用户和角色关联")
@Validated
@AllArgsConstructor
@RestController
@RequestMapping("/sys-user-role")
@Slf4j
public class SysUserRoleController extends BaseController<SysUserRole, SysUserRoleService> {

    /**
    * 添加
    */
    @PostMapping("/add")
    @ApiOperation(value = "添加用户和角色关联")
    public boolean add(@Valid @RequestBody SysUserRole entity){
        return service.save(entity);
    }

    /**
    * 根据id查询
    */
    @GetMapping("/{id}")
    @ApiOperation(value = "根据id查询用户和角色关联")
    public SysUserRole get(@PathVariable("id") Long id){
        return service.getById(id);
    }

    /**
    * 更新
    */
    @PutMapping("/update")
    @ApiOperation(value = "根据id更新用户和角色关联")
    public boolean update(@Valid @RequestBody SysUserRole entity){
        return service.updateById(entity);
    }

    /**
    * 查询
    */
    @GetMapping("/query")
    @ApiOperation(value = "列表查询用户和角色关联")
    public List<SysUserRole> query(SysUserRoleQuery query){
        return service.getByQuery(query);
    }

    /**
    * 分页查询
    */
    @GetMapping("/pageQuery")
    @ApiOperation(value = "分页查询用户和角色关联")
    public PageResult pageQuery(SysUserRoleQuery query){
        return service.getByPageQuery(query);
    }

}

